package com.twb.core.base.entity.vo;

import java.io.Serializable;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.twb.core.util.StringUtil;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/** 
 * @ClassName PageVo 
 * @Description 分页参数接收对象
 * @author DSY
 * @date 2018年10月23日 下午5:14:12 
 */ 
@ApiModel(value="PageVo",description="分页入参对象（兼容bootstrap table）")
public class PageVo implements Serializable{
	
	private static final long serialVersionUID = 1L;

	/** 默认每页显示数 */
	public static final int DEFAULT_PAGE_SIZE = 10;
	
	/**
	 * 当前页
	 */
	@ApiModelProperty(name="pageNum",value="当前页数",example="1",required=false)
	private int pageNum;
	
	/**
	 * 每页行数
	 */
	@ApiModelProperty(name="pageSize",value="每页行数",example="10",required=false)
	private int pageSize;
	
	/**
	 * 当前页（兼容bootstrap table）
	 */
	@ApiModelProperty(hidden=true)
	private int offset;
	
	/**
	 * 每页行数（兼容bootstrap table）
	 */
	@ApiModelProperty(hidden=true)
	private int limit;
	

	/**
	 * 排序列
	 */
	@ApiModelProperty(name="sort",value="排序列",example="id",required=false)
	private String sort;
	
	/**
	 * 排序方式
	 */
	@ApiModelProperty(name="order",value="排序方式",example="desc",required=false)
	private String order;
	
	/**
	 * 驼峰自动转下划线
	 */
	private Boolean convertUnderLine = true;
	
	/**
	 * 是否启用分页
	 */
	@ApiModelProperty(name="enable",value="是否启用分页",example="true",required=false)
	private Boolean enable = true;
	
	@ApiModelProperty(name="fileName",value="导出文件",example="true",required=false)
	private String fileName;
	
	@ApiModelProperty(name="headers",value="导出Excel专用，可用于动态表头导出",required=false)
	private List<TableHeader> headers;
	
	public PageVo() {
		this.offset = this.pageNum = 1;
		this.limit = this.pageSize = DEFAULT_PAGE_SIZE;
	}
	
	public int getPageNum() {
		return pageNum;
	}

	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getOffset() {
		return offset;
	}

	public void setOffset(int offset) {
		this.pageNum = Integer.valueOf(offset/this.limit)+1;
		this.offset = this.pageNum;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.pageSize= limit;
		this.limit = limit;
	}

	public String getSort() {
		return sort;
	}

	public void setSort(String sort) {
		this.sort = sort;
	}

	public String getOrder() {
		if (StringUtils.isBlank(order)) {
			return "";
		}
		return " " + order;
	}

	public void setOrder(String order) {
		this.order = order;
	}
	
	public Boolean getConvertUnderLine() {
		return convertUnderLine;
	}

	public void setConvertUnderLine(Boolean convertUnderLine) {
		this.convertUnderLine = convertUnderLine;
	}

	public Boolean getEnable() {
		return enable;
	}

	public void setEnable(Boolean enable) {
		this.enable = enable;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public List<TableHeader> getHeaders() {
		return headers;
	}

	public void setHeaders(List<TableHeader> headers) {
		this.headers = headers;
	}

	@ApiModelProperty(hidden=true)
	public String getSorts() {
		if(StringUtils.isBlank(this.sort)) {
			return "";
		}
		if(convertUnderLine) {
			String underLine_sort = StringUtil.convertUnderLine(this.sort);
			return underLine_sort + getOrder();
		}else {
			return this.sort + getOrder();
		}
	}
}
